﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ProjScan.RecordManager.AssetData;
using ProjScan.Tools;
using UnityEditor;
using UnityEngine;

namespace ProjScan.RecordManager
{
	// Token: 0x0200028D RID: 653
	internal class TextureRecordManager : RecordManagerBase<TextureAssetData>
	{
		// Token: 0x06001135 RID: 4405 RVA: 0x00050DEC File Offset: 0x0004EFEC
		public override void PrepareAssets()
		{
			this.datas = new List<TextureAssetData>();
			this._textureAssetDataDictionary = new Dictionary<string, TextureAssetData>();
			string[] array = new string[]
			{
				"exr",
				"psd",
				"jpg",
				"jpeg",
				"png",
				"gif",
				"bmp",
				"tga",
				"tif",
				"tiff",
				"iff",
				"pict",
				"dds"
			};
			int num = AssetPathManager.Instance.artPathList.Length;
			for (int i = 0; i < num; i++)
			{
				bool isEditor = Singleton<ScanInfo>.Instance.isEditor;
				if (isEditor)
				{
					EditorUtility.DisplayProgressBar("Proj Scan [" + this.TableTag + "]", string.Concat(new string[]
					{
						"Preparing ",
						this.TableTag,
						"(",
						this.datas.Count.ToString(),
						")..."
					}), (float)i * 1f / (float)num);
				}
				string text = AssetPathManager.Instance.artPathList[i];
				string text2 = Path.GetExtension(text).ToLower().Replace(".", "");
				bool flag = Enumerable.Contains<string>(array, text2);
				if (flag)
				{
					this.ActiveAllRecord();
					bool flag2 = this.CheckAssetPathRules(text);
					if (flag2)
					{
						TextureImporter textureImporter = AssetImporter.GetAtPath(text) as TextureImporter;
						bool flag3 = textureImporter != null;
						if (flag3)
						{
							Texture texture = AssetDatabase.LoadAssetAtPath(text, typeof(Texture)) as Texture;
							int id = AssetPathManager.Instance.GetID(Path.GetDirectoryName(text));
							bool flag4 = texture != null;
							if (flag4)
							{
								TextureAssetData textureAssetData = new TextureAssetData(id, text, texture, textureImporter);
								this._textureAssetDataDictionary.Add(textureAssetData.GUID, textureAssetData);
								textureAssetData.id = this.datas.Count;
								this.ValidateAsset(textureAssetData);
								textureAssetData.Reset();
								this.datas.Add(textureAssetData);
								bool flag5 = this.datas.Count % 100 == 0;
								if (flag5)
								{
									ToolsHelper.GC();
								}
							}
						}
					}
				}
			}
		}

		// Token: 0x06001136 RID: 4406 RVA: 0x00051048 File Offset: 0x0004F248
		public TextureAssetData GetTextureAssetData(string string_0)
		{
			TextureAssetData result = null;
			this._textureAssetDataDictionary.TryGetValue(string_0, out result);
			return result;
		}

		// Token: 0x17000389 RID: 905
		// (get) Token: 0x06001137 RID: 4407 RVA: 0x0005106C File Offset: 0x0004F26C
		public override string TableTag
		{
			get
			{
				return "texture";
			}
		}

		// Token: 0x040009FB RID: 2555
		private Dictionary<string, TextureAssetData> _textureAssetDataDictionary = null;
	}
}
